# uncompyle6 version 2.11.5
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
# [GCC 4.9.2]
# Embedded file name: D:\project\inleader_frist_client\print_client\setting.py
# Compiled at: 2014-01-11 03:41:58
import ConfigParser
import os,uuid
import logging
import logging.handlers

class Vfs:

    @staticmethod
    def getRootDir():
        return os.path.dirname(os.path.abspath(__file__))

    @staticmethod
    def getDirByRoot(dir):
        path = os.path.join(Vfs.getRootDir(), dir)
        if not os.path.exists(path):
            os.mkdir(path)
        return path

    @staticmethod
    def getHtmlDir():
        if setting.config is not None and setting.config.has_option('api', 'html_path'):
            html_path = setting.config.get('api', 'html_path')
            return Vfs.getDirByRoot(str(html_path))
        else:
            return Vfs.getDirByRoot('html_22')
        return

    @staticmethod
    def getTempDir():
        return Vfs.getDirByRoot('temp')

    @staticmethod
    def deleteTempFile(tmp_file):
        if os.path.exists(tmp_file):
            os.remove(tmp_file)
        else:
            tmp_file = os.path.join(Vfs.getTempDir(), tmp_file)
            if os.path.exists(tmp_file):
                os.remove(tmp_file)

    @staticmethod
    def getWebkitCacheDir():
        return Vfs.getDirByRoot('cache')

    @staticmethod
    def getWebkitOfflineDir():
        return Vfs.getDirByRoot('offline')


class Setting:

    def __init__(self):
        self.loadConfig()
        self.loadLogger()

    def loadConfig(self):
        self.config = ConfigParser.ConfigParser()
        config_file = os.path.join(Vfs.getRootDir(), 'config.cfg')
        self.config.readfp(open(config_file))

    def loadLogger(self):
        self.logger = logging.getLogger()
        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
        console = logging.StreamHandler()
        console.setFormatter(formatter)
        self.logger.addHandler(console)
        self.logger.setLevel(logging.ERROR)

    def getMac(self):

        mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
        return mac
        # print(mac)
        # try:
        #     if setting.config is not None and setting.config.has_option('api', 'mac_address'):
        #         address_path = setting.config.get('api', 'mac_address')
        #         f = open(str(address_path), 'r')
        #         mac = f.read()
        #         f.close()
        #         return mac.strip().lower()
        #     f = open('/sys/class/net/eth0/address', 'r')
        #     mac = f.read()
        #     f.close()
        #     return mac.strip().lower()
        # except:
        #     return ''
        #
        # return


setting = Setting()